UNPKG

nuxt-users

Version:

A comprehensive user management module for Nuxt 3 and Nuxt 4 applications with authentication, authorization, database support, and CLI tools

25 lines (24 loc) 740 B
import { createError, defineEventHandler, readBody } from "h3"; import { useRuntimeConfig } from "#imports"; import { updateUser } from "../../utils/user.js"; export default defineEventHandler(async (event) => { const { nuxtUsers } = useRuntimeConfig(); const options = nuxtUsers; const userId = Number(event.context.params?.id); if (!userId) { throw createError({ statusCode: 400, statusMessage: "Invalid user ID" }); } const body = await readBody(event); try { const updatedUser = await updateUser(userId, body, options); return { user: updatedUser }; } catch (error) { throw createError({ statusCode: 500, statusMessage: `Error updating user: ${error.message}` }); } });